﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RockCompany.Master.Model;
using RockCompany.Master.Controller;
using RockCompany.Common.Lib;
using RockCompany.Common.Constant;
using System.IO;

namespace RockCompany.Master.View
{
    public partial class SC02 : Form
    {
        private SC02FormModel loginModel;
        private SC02FormController loginCtrler;
        private Translator trans;
        private SC01 frm_SC01;
        private int nTime = 0;

        public SC02()
        {
            loginModel = new SC02FormModel();
            loginCtrler = new SC02FormController();
            trans = new Translator();
            loginModel.translator = trans;
            InitializeComponent();
        }

        private void button_Login_Click(object sender, EventArgs e)
        {
            string sErr = "", sCap = "";
            if (loginCtrler.isValid(textbox_Username.Text, textbox_Password.Text))
            {
                if (loginModel.checkLogin(textbox_Username.Text, textbox_Password.Text))
                {
                    this.Hide();
                    frm_SC01 = new SC01(trans, textbox_Username.Text, this);
                    frm_SC01.Show();
                    //if (timer_TimeLimitation.Enabled)
                    //    timer_TimeLimitation.Start();
                    //else
                    //    frm_SC01.lockForm();
                }
                else
                    sErr = trans.getMessageCaption(CommonConstantIF.LoginError);
            }
            else
                sErr = trans.getMessageCaption(CommonConstantIF.InputMissing);
            if (sErr != "")
            {
                sCap = trans.getMessageCaption(CommonConstantIF.ErrorBoxCap);
                InforDialog.showErrorBox(this, sErr, sCap);
            }
        }

        private void radioButton_VietNameseLang_CheckedChanged(object sender, EventArgs e)
        {
            trans.LocationLang = CommonConstantIF.Language.VN;
        }

        private void radioButton_ChineseLang_CheckedChanged(object sender, EventArgs e)
        {
            trans.LocationLang = CommonConstantIF.Language.CH;
        }

        private void timer_TimeLimitation_Tick(object sender, EventArgs e)
        {
            nTime += 60;
        }

        private void SC02_FormClosing(object sender, FormClosingEventArgs e)
        {
            //string sPth = Path.GetFullPath(Application.StartupPath + DBConnector.SOLUTION_DIR + CommonConstantIF.sTrialTimePath);
           
            //string sPth = Path.GetFullPath(Application.StartupPath + CommonConstantIF.sTrialTimePath);
            //bool b = File.Exists(sPth);
            //if (b)
            //{
            //    TrialTime ttime = (TrialTime)Util.readSerialized(sPth);
            //    if (ttime.Days < TrialTime.nTrialDays)
            //    {
            //        ttime.Minutes += nTime;
            //        ttime.cal();
            //        Util.saveSerialized(ttime, sPth);
            //    }
            //}
        }

        private void SC02_Load(object sender, EventArgs e)
        {
            //string sPth = Path.GetFullPath(Application.StartupPath + DBConnector.SOLUTION_DIR + CommonConstantIF.sTrialTimePath);
            
            //string sPth = Path.GetFullPath(Application.StartupPath + CommonConstantIF.sTrialTimePath);
            //bool b = File.Exists(sPth);
            //if (b)
            //{
            //    TrialTime ttime = (TrialTime)Util.readSerialized(sPth);
            //    timer_TimeLimitation.Enabled = (ttime.Days < TrialTime.nTrialDays);
            //}
        }
    }
}
